﻿using System.Windows;
using System.Windows.Controls;

namespace ZOIL.Framework.Presentation
{
    /// <summary>
    /// 
    /// </summary>
    public class ZComponentFrame : Viewbox
    {
        #region dp

        /// <summary>
        /// 
        /// </summary>
        public double WidthNeeded
        {
            get { return (double)GetValue(WidthNeededProperty); }
            set { SetValue(WidthNeededProperty, (double)value); }
        }

        #endregion

        #region attached properties

        /// <summary>
        /// 
        /// </summary>
        public static readonly DependencyProperty WidthNeededProperty = DependencyProperty.RegisterAttached("WidthNeeded", typeof(double), typeof(ZComponentFrame), new UIPropertyMetadata(0.0));

        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static double GetWidthNeeded(DependencyObject obj)
        {
            return (double)obj.GetValue(WidthNeededProperty);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        public static void SetWidthNeeded(DependencyObject obj, double value)
        {
            obj.SetValue(WidthNeededProperty, value);
        }

        #endregion

        #region ctor

        /// <summary>
        /// 
        /// </summary>
        public ZComponentFrame()
        {
            Visibility = Visibility.Collapsed;
        }

        #endregion

        #region public methods

        /// <summary>
        /// 
        /// </summary>
        public void Show()
        {
            if (Visibility == Visibility.Collapsed)
                Visibility = Visibility.Visible;

            if (Child.Visibility == Visibility.Collapsed)
                Child.Visibility = Visibility.Visible;
        }

        /// <summary>
        /// 
        /// </summary>
        public void Hide()
        {
            if (Child.Visibility == Visibility.Visible)
                Child.Visibility = Visibility.Collapsed;
        }

        #endregion
    }
}
